/**
 * 
 */
package leetCode;

/**
 * 把矩阵转置，A[i][j]=A[j][i]
 * 
 * @author zhong
 */
public class TransposeMatrix {
	public int[][] transpose(int[][] A) {
		int n = A.length;
		int m = A[0].length;
		int[][] res = new int[m][n];
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < A[0].length; j++) {
				res[j][i] = A[i][j];
			}
		}
		return res;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[][] A = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
		A = new TransposeMatrix().transpose(A);
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < A[0].length; j++) {
				System.out.print(A[i][j] + " ");
			}
			System.out.println();
		}

	}

}
